// New Grid 를 위한 Script 모음

function fnResetGrid(gridNo)
{
	// 그리드 초기화
	$("#"+"loadingDiv"+gridNo).css("display","");			
	$("#"+"gridBody"+gridNo).css("display","none");	
	 $("#"+"pager"+gridNo).html("");
}

function fnNewLoading(gridNo)
{
	// 그리드 로딩 이미지 노출
	$("#"+"noResult"+gridNo).css("display","none");			
	$("#"+"gridBody"+gridNo).css("display","");	
	var load = "<div><img src=\"/img/loading_icon.gif\" style=\"margin-top:100px\"></div>";
	$("#"+"gridBody"+gridNo).html(load);
}

function fnDrawCell(arrVal, bgColor, arrWidth, arrAlign, style, link, cellLink) // cellLink : 해당 Cell에 대한 Link 여부
{
	// 그리드의 Cell을 구성하는 함수
	var rowCnt = arrVal.length;
	var divs = "<div style=\"clear:both\">";
	var showStyle = "";
	for (r=0; r<rowCnt; r++)
	{
		var click = "";
		if (cellLink[r] == "") 
		{
			click = "onClick=\""+link+"\"";
			showStyle = style + ";cursor:pointer;";
		}
		else 
		{
			click = "";
			showStyle = style + "";
		}
		divs += "	<div style=\"background-color:"+bgColor+";width:"+arrWidth[r]+";text-align:"+arrAlign[r]+";"+showStyle+"\" "+click+">"+arrVal[r]+"</div>";
	}
	divs += "</div>";
	return divs;
}

function fnDrawCell2(arrVal, bgColor, arrWidth, arrAlign, style, link, cellLink) // cellLink : 해당 Cell에 대한 Link 여부
{
	// 그리드의 Cell을 구성하는 함수
	var rowCnt = arrVal.length;
	var divs = "<div style=\"clear:both\">";
	if (style == "lock") var showStyle = "background-image:url('/antioch/img/icon_lock.gif');background-repeat:no-repeat;background-position:3px 5px;";

	for (r=0; r<rowCnt; r++)
	{
		if (r==2)
		{
			if (style == "lock") showStyle = "background-image:url('/antioch/img/icon_lock.gif');background-repeat:no-repeat;background-position:3px 5px;";
		}
		else 
		{
			if (style == "lock") showStyle = "";
		}
		var click = "";
		if (cellLink[r] == "") 
		{
			click = "onClick=\""+link+"\"";
			showStyle += ";cursor:pointer;";
		}
		divs += "	<div style=\"background-color:"+bgColor+";width:"+arrWidth[r]+";text-align:"+arrAlign[r]+";"+showStyle+"\" "+click+">"+arrVal[r]+"</div>";
	}
	divs += "</div>";
	return divs;
}

function fnNewPaging(method, totalRows, curPage, pageLimit)
{
	var totalPage = Math.ceil((totalRows/pageLimit));
	var startPageNo = "";
	if (curPage%10 == 0) startPageNo = (Math.floor(curPage/10)-1)*10;
	else startPageNo = Math.floor(curPage/10)*10;
	if (startPageNo == 0) startPageNo = 1;
	var endPageNo = parseInt(startPageNo,10)+10;
	if (endPageNo > totalPage) endPageNo = totalPage+1;

	var prevPage = "";
	var prevPageNo = parseInt(curPage,10) - 1;
	prevPage = "<span onClick=\""+method+"('"+prevPageNo+"')\" class=\"page_box\" style=\"cursor:pointer;\"><p style=\"margin-top:3px\"> < </p></span>";
	if (prevPageNo<1) prevPage = "<span class=\"page_box\"><p style=\"margin-top:3px\"> < </p></span>";
	
	//alert(startPageNo+'/'+endPageNo);
	var nextPage = "";
	var nextPageNo = parseInt(curPage,10) + 1;
	nextPage = "<span onClick=\""+method+"('"+nextPageNo+"')\" class=\"page_box\" style=\"cursor:pointer;\"><p style=\"margin-top:3px\"> > </p></span>";
	if (nextPageNo > totalPage) nextPage = "<span class=\"page_box\"><p style=\"margin-top:3px\"> > <p></span>";

	var pager = "";
	for (c=startPageNo; c<endPageNo; c++)
	{
		pager += "";
		if (curPage == c) pager += "<span class=\"page_box\" onClick=\""+method+"('"+c+"')\" style=\"cursor:pointer;font-weight:bold\"><p style=\"margin-top:3px;padding-left:0px\">"+c+"</p></span>";
		else pager += "<span class=\"page_box\" onClick=\""+method+"('"+c+"')\" style=\"cursor:pointer;\"><p style=\"margin-top:3px;padding-left:0px\">"+c+"</p></span>";
	}
	var rsPage = new Array();
	rsPage['prev'] = prevPage;
	rsPage['pager'] = pager;
	rsPage['next'] = nextPage;
	return rsPage;
}

// 그리드의 부가정보 표시 또는 가리기
function fnGridExtraInfo(gridNo, ttlCnt, page, limit)
{
	$("#grid0"+gridNo+"Cnt").html(ttlCnt);
	if (ttlCnt > 0)
	{				
		$("#"+"noResult"+gridNo).css("display","none");			
		$("#"+"gridBody"+gridNo).css("display","");		
		$("#"+"gridBody"+gridNo).html("");
		var paging = fnNewPaging("grid0"+gridNo+"List", ttlCnt, page, limit);
		var pages = paging['prev'] + paging['pager'] + paging['next'];
		$("#pager"+gridNo).html(pages);
	}
	else
	{
		$("#"+"noResult"+gridNo).css("display","");			
		$("#"+"gridBody"+gridNo).css("display","none");		
	}
}

// 그리드 헤더의 Cell의 width를 배열로 리턴
function fnGetGridCellWidth(gridNo)
{	
	// 그리드 헤더를 기준으로 Cell의 폭을 구해온다.
	var cellWidth = new Array();
	for (var c=0; c<$("#gridHeader"+gridNo+" div").length; c++)
	{
		cellWidth[c] = $("#gridHeader"+gridNo+" div").eq(c).css("width");
	}
	return cellWidth;
}
